import Vue from 'vue'
import Vuex from 'vuex'

import {
  bbsCommentQuery,
  bbsCommentDelete,
  bbsCommentAdd,
  bbsCommentUpdate,
  bbsCommentQueryById,
} from '@/api/bbs/bbsComment'

Vue.use(Vuex)

const state = {}

const getters = {}

const actions = {
  //评论增删改查
  async queryBbsComment({ commit }, listQuery) {
    let res = await bbsCommentQuery({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async queryBbsCommentById({ commit }, id) {
    let res = await bbsCommentQueryById(id)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async delBbsComment({ commit }, row) {
    let res = await bbsCommentDelete(row.id)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async addBbsComment({ commit }, data) {
    let res = await bbsCommentAdd(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async updateBbsComment({ commit }, data) {
    let res = await bbsCommentUpdate(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
}

const mutations = {}

export default {
  state,
  getters,
  actions,
  mutations,
}
